/**
 * 是否符合 16 进制颜色值
 * @param str String
 * @returns Boolean
 */
export const isHexColor = (str: string): boolean => /^#[0-9A-F]{6}$/i.test(str);

/**
 * 是否符合手机号码
 * @param str
 * @returns
 */
export const isPhoneNumber = (str: string | number): boolean => {
    let input = `${str}`;
    return /^1\d{10}$/.test(input);
};

/**
 * 是否符合邮箱
 * @param input string
 * @returns boolean
 */
export function isEmail(input: string): boolean {
    const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    return regex.test(input);
}

/**
 * 判断是否为空
 * @param {*} value
 * @returns {boolean}
 */
export const isEmpty = (value: any): boolean => {
    switch (typeof value) {
        case 'undefined':
            return true;
        case 'string':
            if (value.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
            break;
        case 'boolean':
            if (!value) return true;
            break;
        case 'number':
            if (0 === value || isNaN(value)) return true;
            break;
        case 'object':
            if (null === value || value.length === 0) return true;
            for (var i in value) {
                return false;
            }
            return true;
    }
    return false;
};
